<!DOCTYPE html>
<html>
<head>
	<title>dplayer播放器</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=11" />
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport">
    
	<style type="text/css">
	html,body{width:100%;height:100%; padding:0; margin:0;}
	#playerCnt{width:100%;height:100%;position: relative;}
    .dplayer-video-current{
		width: 100%;
	}
	</style>
	<link rel="stylesheet" href="/static/player/dplayer/DPlayer.min.css">
	<link rel="stylesheet" href="/static/player/dplayer/dplayer.css">
	<script type="text/javascript" src="/static/player/dplayer/flv.min.js"></script>
	<script type="text/javascript" src="/static/player/dplayer/hls.min.js"></script>
	<script type="text/javascript" src="/static/player/dplayer/dash.all.min.js"></script>
	<script type="text/javascript" src="/static/player/dplayer/webtorrent.min.js"></script>
	<script type="text/javascript" src="/static/player/dplayer/DPlayer.min.js"></script>
	<script type="text/javascript" src="/static/js/jquery.js"></script>
</head>
<body marginwidth="0" marginheight="0">
<div id="playerCnt"></div>
<script type="text/javascript">
    var type='normal';
    var live=false;
    
    if(parent.MacPlayer.PlayUrl.indexOf('.m3u8')>-1){
        type='hls';
        live=true;
    }
    else if(parent.MacPlayer.PlayUrl.indexOf('magnet:')>-1){
        type='webtorrent';
    }
    else if(parent.MacPlayer.PlayUrl.indexOf('.flv')>-1){
        type='flv';
    }
    else if(parent.MacPlayer.PlayUrl.indexOf('.mpd')>-1){
        type='dash';
    }
    var dp = new DPlayer({
        container: document.getElementById('playerCnt'),
        autoplay: true,
        screenshot: false,
        video: {
            url: parent.MacPlayer.PlayUrl,
            live: live,
            pic:'',
            type:type
        },
        contextmenu: [

        ]
    });
    
    dp.on('loadeddata',function(){
        let href=window.parent.location.href
        let progress=''
        if(href.indexOf('ulog_watch_progress')!=-1){
            progress= Number(href.split('ulog_watch_progress=')[1])
            let continueTime=(progress/100)*dp.video.duration
            if(continueTime>0){
                dp.seek(continueTime)
            }
        }
　　});

    let url=parent.MacPlayer.Link
    let vod_id=Number(url.split('/play/id/')[1].split('/')[0])
    let sid=Number(url.split('/sid/')[1].split('/')[0])
    let nid=Number(url.split('/nid/')[1].split('.html')[0])
    $(window).on('beforeunload',function(e){
        let percent=Number(((dp.video.currentTime/dp.video.duration)*100).toFixed(0)) 
        if(percent<=0)return
        $.ajax({
            url:`/ajax/watch_progress?vod_id=${vod_id}&sid=${sid}&nid=${nid}&watch_progress=${percent}`,
            type:'get',
            dataType:'json',
            timeout: 5000,
            success:function(data){
                console.log('请求数据',data);
            },
            
        })
    })
    
    dp.on('ended',function(){
　　　　if(parent.MacPlayer.PlayLinkNext!=''){
            top.location.href = parent.MacPlayer.PlayLinkNext;
        }
　　});
    
	try{
		//document.getElementById('playerCnt').style.height = parent.MacPlayer.Height + 'px';
	}
	catch(e){}
</script>
</body>
</html>